/**
 *  我的优惠券
 */


import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/coupon_item.dart';
import 'package:cbec_app/components/common/my_coupon_item.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/my/controller/my_coupon_ctr.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MyCoupon extends StatelessWidget {
  MyCoupon({super.key});

  final MyCouponController CouponCtr = Get.put((MyCouponController()));

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: "我的优惠券",
      iconType: IconType.back,
      isShowPadding: true,
      paddingTop: 10.h,
      children: [
        //这里是上方的tabbar
        _typeTabs(),
        SizedBox(height: 5,),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
             _StateTabbar(),
            
            BaseInteractive(
              onClick: () => {
                Get.toNamed(Routes.couponCenter)
              },
              childWidget: Container(
              child: Row(
              children: [
                  const Text("前往领券中心"),
                  SizedBox(width: 5.w,),
                  const Icon(Icons.arrow_forward_ios,size: 12,)
              ],
            ),
            ),
            )
          ],
        ),
       
        //红包容器
        Container(
          height: 600,
          margin: EdgeInsets.only(top: 10.w),
          // color: Colors.red,
          child: Obx(() =>CouponCtr.dataList.isNotEmpty?  Tools.getPullRefresh(
            enablePullDown: true,
            enablePullUp: CouponCtr.hasNextPage,
            refreshController: CouponCtr.baseRefreshCtr,
                  onRefresh: CouponCtr.onPageRefresh,
                  onLoading: CouponCtr.onPageLoading,
                  child: ListView.builder(
                      itemCount: CouponCtr.dataList.length,
                      itemBuilder: (context, index) {
                        final item = CouponCtr.dataList[index];
                        return MyCouponItem(status: item['status'], item: item);
                      })
          ):const NotFound())
          // ListView(
          //   children: [
          //     // CouponItem(price: "1.5", needMoney: "15", start_time: "2021.05.22", end_time: "2023.06.18", title: "满减券", sub_title: "满20块可用", desc: "这里是个描述和说明呢", status: 1, status_tetx: '去使用'),
          //     // CouponItem(price: "1.5", needMoney: "15", start_time: "2021.05.22", end_time: "2023.06.18", title: "满减券", sub_title: "满20块可用", desc: "这里是个描述和说明呢", status: 2, status_tetx: '已使用')
          //   ],
          // ),
        ),
      ],
    );
  }

  /**
   *  类型筛选
   */
  Widget _typeTabs() => SizedBox(
        height: 25,
        child: Obx(() => TabBar(
            dividerColor: Colors.transparent,
            indicator: BoxDecoration(),
            labelColor: Tools.fromHex("#F83F2D"),
            unselectedLabelColor: Colors.black,
            controller: CouponCtr.typeTabController,
            isScrollable: true,
            padding: EdgeInsets.zero,
            labelPadding: EdgeInsets.only(right: 25.w),
            tabAlignment: TabAlignment.start,
            tabs: List.generate(CouponCtr.typeList.length, (index) {
              return Tab(
                text: index>0?"${CouponCtr.typeList[index]['label']}(${CouponCtr.typeList[index]['value']})" :CouponCtr.typeList[index]['label']
              );
            })
            )),
      );


  /**
   *  状态筛选
   */
  Widget _StateTabbar() => SizedBox(
        height: 25,
        child: TabBar(
            dividerColor: Colors.transparent,
            indicator: const BoxDecoration(
              border: Border(
                bottom: BorderSide(width: 0.8, color: Colors.black),
              ),
            ),
            labelColor: Colors.black,
            unselectedLabelColor: Color.fromRGBO(153, 153, 153, 1),
            controller: CouponCtr.tabController,
            isScrollable: true,
            padding: EdgeInsets.zero,
            labelPadding: EdgeInsets.only(right: 10.w),
            tabAlignment: TabAlignment.start,
            tabs: const [
              Tab(
                text: "未使用",
              ),
              Tab(
                text: "已使用",
              ),
              Tab(
                text: "已过期",
              ),
            ]),
      );
}
